package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.MemberMapper;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.apache.dubbo.config.annotation.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/17 17:30
 * @description：
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
    @Override
    public Member findMemeberByTelephone(String telephone) {
        return baseMapper.findMemeberByTelephone(telephone);
    }

    @Override
    public Long saveMember(Member member) {
        this.saveOrUpdate(member);
        return member.getId();
    }

    @Override
    public Map selectMemberSexPercent() {
        HashMap map = new HashMap();
        List<Map> data = this.baseMapper.selectMemberSexPercent();
        map.put("seriesData",data);
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < data.size(); i++) {
            Map _map = data.get(i);
            String sex =  _map.get("name").toString();
            if("1".equals(sex)){
                _map.put("name","男");
            }else if("2".equals(sex)){
                _map.put("name","女");
            }
            list.add( _map.get("name").toString());
        }
        map.put("legendData",list);
        System.out.println("map = " + map);
        return map;
    }

    @Override
    public Map selectMemberNumLineChart(String startData, String endData) {
        HashMap map = new HashMap();
        List<Map> data = this.baseMapper.selectMemberNumLineChart(startData,endData);
        ArrayList<String> date = new ArrayList<>();
        ArrayList<Integer> values = new ArrayList<>();
        for (Map _map : data) {
            date.add( _map.get("create_date").toString());
            Object value = _map.get("value");
            values.add( Integer.parseInt(_map.get("value").toString()));
        }
        map.put("dateTimeList",date);
        map.put("numberList",values);
        return map;
    }
}
